package com.dbky.alg.browser.session;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.security.web.session.SessionInformationExpiredEvent;
import org.springframework.security.web.session.SessionInformationExpiredStrategy;

import javax.servlet.ServletException;
import java.io.IOException;

/**
 * @Auther: tianchao
 * @Date: 2021/12/15 21:56
 * @Description:
 */
public class AlgSessionInformationExpiredStrategy extends AbstractSessionStrategy implements SessionInformationExpiredStrategy {

    public static final Logger logger = LoggerFactory.getLogger(AlgSessionInformationExpiredStrategy.class);

    public AlgSessionInformationExpiredStrategy(String invalidSessionUrl) {
        super(invalidSessionUrl);
    }

    @Override
    public void onExpiredSessionDetected(SessionInformationExpiredEvent event) throws IOException, ServletException {
        logger.info("session信息{}",event.getSessionInformation());
        Object source = event.getSource();
        logger.info("source: {}",source);
        onSessionInvalid(event.getRequest(),event.getResponse());
    }

    /**
     * session失效是否是并发导致的
     *
     * @return
     */
    protected boolean isConcurrency() {
        return true;
    }



}
